<template>
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button style="float:right" type="primary" @click="handleSearchList()" size="small">查询搜索</el-button>
        <el-button
          style="float:right;margin-right: 15px"
          @click="handleResetSearch()"
          size="small"
        >重置</el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input v-model="listQuery.orderNumber" class="input-width" placeholder="订单编号"></el-input>
          </el-form-item>
          <el-form-item label="用户名/手机号码：">
            <el-input v-model="listQuery.phoneOrwxName" class="input-width" placeholder="姓名/手机号码"></el-input>
          </el-form-item>
          <el-form-item label="电梯编号：">
            <el-input v-model="listQuery.liftNumber" class="input-width" placeholder="电梯编号"></el-input>
          </el-form-item>
          <el-form-item label="是否支付：">
            <el-select v-model="listQuery.pay" class="input-width" clearable placeholder="全部">
              <el-option label="已支付" value="1"></el-option>
              <el-option label="未支付" value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <el-table
        ref="orderTable"
        :data="list"
        style="width: 100%;"
        @selection-change="handleSelectionChange"
        v-loading="listLoading"
        border
      >
        <el-table-column type="selection" width="60" align="center"></el-table-column>
        <el-table-column label="订单编号" width="180" align="center">
          <template slot-scope="scope">{{scope.row.orderNumber}}</template>
        </el-table-column>
        <el-table-column label="提交的用户" width="180" align="center">
          <template slot-scope="scope">{{scope.row.wxName }}</template>
        </el-table-column>
        <el-table-column label="用户手机号" width="180" align="center">
          <template slot-scope="scope">{{scope.row.phone }}</template>
        </el-table-column>
        <el-table-column label="选择日期" width="180" align="center">
          <template slot-scope="scope">{{scope.row.hasCheckWeek | filterHasCheckWeek}}</template>
        </el-table-column>
        <el-table-column label="素材类型" width="120" align="center">
          <template slot-scope="scope">{{scope.row.sucaiType}}</template>
        </el-table-column>
        <el-table-column label="投放时长" width="120" align="center">
          <template slot-scope="scope">{{scope.row.time }}s</template>
        </el-table-column>
        <el-table-column label="电梯编号" width="120" align="center">
          <template slot-scope="scope">{{ scope.row.liftNumber }}</template>
        </el-table-column>
        <el-table-column label="楼盘名称" width="120" align="center">
          <template slot-scope="scope">{{scope.row.name }}</template>
        </el-table-column>
        <el-table-column label="楼盘地址" width="120" align="center">
          <template slot-scope="scope">{{scope.row.address }}</template>
        </el-table-column>
        <el-table-column label="总价格" width="120" align="center">
          <template slot-scope="scope">{{scope.row.totalPrice }}</template>
        </el-table-column>
        <el-table-column label="是否支付" width="120" align="center">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay === '0'">未支付</el-tag>
            <el-tag type="success" v-if="scope.row.pay === '1'">已支付</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleDeleteOrder(scope.row)"
              v-show="scope.row.delCd === '1'"
            >删除订单</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="batch-operate-container">
      <el-select size="small" v-model="operateType" placeholder="批量操作">
        <el-option
          v-for="item in operateOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-button
        style="margin-left: 20px"
        class="search-button"
        @click="handleBatchOperate()"
        type="primary"
        size="small"
      >确定</el-button>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import { fetchList, deleteOrder } from "@/api/aorder";
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  orderNumber: "",
  phoneOrwxName: "",
  pay: "",
  liftNumber: ""
};
export default {
  name: "orderList",
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      listLoading: true,
      list: null,
      total: null,
      operateType: null,
      multipleSelection: [],
      operateOptions: [
        {
          label: "删除订单",
          value: 1
        }
      ],
      logisticsDialogVisible: false
    };
  },
  created() {
    this.getList();
  },
  filters: {
    filterHasCheckWeek(val) {
      return val[0].replace('[ "', "").replace('" ]', "");
    }
  },
  methods: {
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
    },
    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleDeleteOrder(row) {
      let ids = [];
      ids.push(row.keyId);
      this.deleteOrder(ids);
    },
    handleBatchOperate() {
      if (this.multipleSelection == null || this.multipleSelection.length < 1) {
        this.$message({
          message: "请选择要操作的订单",
          type: "warning",
          duration: 1000
        });
        return;
      }
      if (this.operateType === 1) {
        //删除订单
        let ids = [];
        for (let i = 0; i < this.multipleSelection.length; i++) {
          ids.push(this.multipleSelection[i].keyId);
        }
        this.deleteOrder(ids);
      }
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    getList() {
      this.listLoading = true;
      fetchList(this.listQuery).then(response => {
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
    deleteOrder(ids) {
      this.$confirm("是否要进行该删除操作?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteOrder({ ids: ids }).then(response => {
          if (response.isSuccee) {
            this.$message({
              message: "删除成功！",
              type: "success",
              duration: 1000
            });
            this.getList();
          } else {
            this.$message({
              message: "删除失败！",
              type: "error",
              duration: 1000
            });
          }
        });
      });
    }
  }
};
</script>
<style scoped>
.input-width {
  width: 203px;
}
</style>


